//
//  HNSH_MyTeamProgress.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/28.
//

#import "HNSH_MyTeamProgress.h"

@interface HNSH_MyTeamProgress ()

/* progressBottom */
@property(nonatomic, strong) UIView *progressBottom;
/* progressTop */
@property(nonatomic, strong) UIView *progressTop;

@end

@implementation HNSH_MyTeamProgress

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}


- (void)setProgress:(CGFloat)progress {
    self.progressTop.frame = CGRectMake(0, 0, (kScreenWidth-64)*progress, 8);
}

- (void)setTopColor:(UIColor *)topColor {
    _topColor = topColor;
    self.progressTop.backgroundColor = topColor;
    self.desLabel.textColor = topColor;
}

- (void)addAllViews {
    [self addSubview:self.progressBottom];
    [self.progressBottom addSubview:self.progressTop];
    
    [self addSubview:self.titleLabel];
    [self addSubview:self.desLabel];
}

- (void)addAllLayout {
    
    [self.progressBottom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(10);
    }];
    [self clipCornerWithView:self.progressBottom cornerWidth:5 cornerType:UIRectCornerAllCorners];
    
    self.progressTop.frame = CGRectMake(0, 0, 0, 10);
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.progressBottom.mas_top).offset(-8);
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(20);
    }];
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.progressBottom.mas_top).offset(-8);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(20);
    }];
}

#pragma mark lazy
- (UIView *)progressBottom {
    if (!_progressBottom) {
        _progressBottom = [[UIView alloc]init];
        _progressBottom.backgroundColor = [UIColor colorWithHexString:@"#EBEBEB"];
    }
    return _progressBottom;
}

- (UIView *)progressTop {
    if (!_progressTop) {
        _progressTop = [[UIView alloc]init];
        _progressTop.backgroundColor = [UIColor appGreenColor];
        _progressTop.layer.cornerRadius = 5;
        _progressTop.layer.masksToBounds = YES;
    }
    return _progressTop;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"";
        _titleLabel.textColor = [UIColor appGray666LabelColor];
        _titleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _titleLabel;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]init];
        _desLabel.text = @"";
        _desLabel.textColor = [UIColor appGreenColor];
        _desLabel.font = [UIFont systemFontOfSize:14];
    }
    return _desLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
